﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HtmlSanitizer
{
    public class InvalidHtmlException : Exception 
    {
        private TidyNet.TidyMessageCollection messages;

        //
        // Summary:
        //     Initializes a new instance of the InvalidHtmlException class with a specified
        //     error message.
        //
        // Parameters:
        //   message:
        //     The message that describes the error.
        public InvalidHtmlException(TidyNet.TidyMessageCollection messages)
        {
            this.messages = messages;
        }

        public override string Message
        {
            get
            {
                StringBuilder builder = new StringBuilder();
                builder.Append(base.Message); 
                foreach (TidyNet.TidyMessage msg in messages)
                {
                    if (msg.Level == TidyNet.MessageLevel.Error)
                    {
                        builder.Append("\n");
                        builder.Append(msg.ToString());
                    }
                }

                return builder.ToString();
            }
        }
    }
}
